#include "irq.h"
#include "time.h"
#include "sched.h"
#include "string.h"
#include "screen.h"

/* exception handler */
uint64_t exception_handler[32];

/* used to init PCB */
uint32_t initial_cp0_status;

// extern void do_shell();

static void irq_timer()
{
    screen_reflush();
    /* increase global time counter */
    time_elapsed += TIMER_INTERVAL;
    /* reset timer register */
    reset_timer(TIMER_INTERVAL);
    /* sched.c to do scheduler */
    do_scheduler();
}

void other_exception_handler()
{
    time_elapsed += TIMER_INTERVAL;
}

void interrupt_helper(uint32_t status, uint32_t cause)
{
    current_running->type = KERNEL_PROCESS;
    uint32_t interrupt;
    interrupt = (cause & 0xff00) >> 8;
    if(interrupt == 0x80){
        irq_timer();
    } 
    else
    {
        other_exception_handler();
    }
    
}

void change_state(void){
    current_running->type = USER_PROCESS;
}

